package org.gap.jseed;

import java.util.Arrays;
import java.util.List;

import org.gap.jseed.bean.BeanBehaviorInjector;
import org.gap.jseed.contract.ContractServiceInjector;
import org.gap.jseed.injection.ServiceFactoryInjectorFactory;
import org.gap.jseed.injection.TryCatchInjector;
import org.gap.jseed.injection.annotation.EnvironmentInjectionBuilder;
import org.gap.jseed.threading.SwingThreadInjector;


public class SeedContainerFactory {
	private static final List<? extends BuilderFactory> allBuilderFactories = Arrays.asList();
	private static final List<? extends Injector> allInjectors = Arrays.asList(
			new BeanBehaviorInjector(), ContractServiceInjector.withAllAnnotations(), 
			new EnvironmentInjectionBuilder(), 
			new ServiceFactoryInjectorFactory(), 
			new SwingThreadInjector(),
			new TryCatchInjector());
	
	public static SeedContainer newContainer() {
		return newContainer(allBuilderFactories, allInjectors);
	}

	public static SeedContainer newContainer(Iterable<? extends BuilderFactory> builderFactories, Iterable<? extends Injector> injectorFactories) {
		ServiceStoreContainer serviceStore = new ServiceStoreContainer();
		registerBuilderFactories(builderFactories, serviceStore);
		registerInjectorFactories(injectorFactories, serviceStore);
		return serviceStore;
	}

	private static void registerInjectorFactories(Iterable<? extends Injector> injectorFactories, ServiceStoreContainer serviceStore) {
		for (Injector each : injectorFactories) {
			serviceStore.registerInjector(each);
		}
	}

	private static void registerBuilderFactories(Iterable<? extends BuilderFactory> builderFactories, ServiceStoreContainer serviceStore) {
		for (BuilderFactory each : builderFactories) {
			serviceStore.registerBuilderFactory(each);
		}
	}
}
